package Homework;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.stream.Collectors;

public class WriteBackAfterSorted {

	public static void main(String[] args) throws IOException {
		String txt = "cn.txt";
		ArrayList<String> list = new ArrayList<String>();
		
		FileReader fr = new FileReader(txt);		
		int read = 0;
		while((read=fr.read())!=-1){
			list.add((char) read+"");
		}		
		String sorted = list.stream().filter(c->!c.equals("-")).sorted().collect(Collectors.joining("-"));
		fr.close();
		
		FileWriter fw = new FileWriter(txt);
		fw.write(sorted);
		fw.flush();
		fw.close();
	}

	
}
